package gameEngine.com.state;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint.Style;
import android.view.KeyEvent;
import android.view.MotionEvent;
import gameEngine.com.*;
import gameEngine.com.Actor.Actor;

public class StateMainMenu extends MainActivity {

	public static int[] menu = { R.string.STRING_PLAYGAME, R.string.STRING_OPTION,
			R.string.STRING_HELP, R.string.STRING_ABOUT, R.string.STRING_EXIT };
	public static int menuTopX = 130;
	public static int menuTopY = 160;
	public static int menuElementWidth = 270;
	public static int menuElementHeight = 55;
	public static int menuElementSpace = 10;
	public static int menuTouchOffsetX = -137;
	public static int menuTouchOffsetY = -27;
	public static int menuTextOffsetX = 0;
	public static int menuTextOffsetY = 0;

	// String mess = getResources().getString(R.string.mess_1)
	public static void SendMessageStateMainMenu(int type) {
		switch (type) {
		case MESSAGE_CTOR:
			if (spriteMenuButton == null)
				spriteMenuButton = new Sprite("sprite/ui/menubutton.spr", true);
			if (spriteMenu == null)
				spriteMenu = new Sprite("sprite/ui/menu.sprt");
			StateConfirm.setConfirmDeActive();
			break;
		case MESSAGE_UPDATE:
			if (StateConfirm.isConfirm) {
				StateConfirm.SendMessageStateConfirm(MESSAGE_UPDATE);
				return;
			}
			
			UpdateMainmenu();
			
			break;
		case MESSAGE_PAINT:
			//mainCanvas.drawColor(Color.BLACK);
			DrawBackGroundMenu();
			if (StateConfirm.isConfirm)
				StateConfirm.SendMessageStateConfirm(MESSAGE_PAINT);
			break;
		case MESSAGE_DTOR:
			break;
		}
	}
	
	public static void UpdateMainmenu(){
		for (int i = 0; i < menu.length; i++) {
			if (isTouchReleaseInRect(menuTopX + menuTouchOffsetX, menuTopY
					+ menuTouchOffsetY + i
					* (menuElementHeight + menuElementSpace),
					menuElementWidth, menuElementHeight)) {
				switch (menu[i]) {
				case R.string.STRING_PLAYGAME:
					StateGameplay.showHint = false;
				//	StateLoading.loadingtype = StateLoading.LOADING_TYPE_GAME_TO_GAME;					
					MainActivity.changeState(STATE_SELECT_LEVEL);						
					break;					
				case R.string.STRING_ABOUT:
					changeState(STATE_ABOUT);
					break;
				case R.string.STRING_HELP:
					changeState(STATE_HELP);
					break;
				case R.string.STRING_EXIT:
					StateConfirm.setConfirmActive(R.string.STRING_EXIT_COFIRM);						
					break;
				}
			}
		}

	}
	
	public static void DrawBackGroundMenu(){
		if (splashImage != null)
			mainCanvas.drawBitmap(splashImage, 0, 0, null);
		if (spriteMenu != null)
			spriteMenu.drawAFrame(mainCanvas, 2, 0, 0);
		for (int i = 0; i < menu.length; i++) {
			if (!StateConfirm.isConfirm && isTouchDrapInRect(menuTopX + menuTouchOffsetX, menuTopY
					+ menuTouchOffsetY + i
					* (menuElementHeight + menuElementSpace),
					menuElementWidth, menuElementHeight)) {
				spriteMenu.drawAFrame(mainCanvas, 1, menuTopX,
						menuTopY + i
								* (menuElementHeight + menuElementSpace));
			} else if (spriteMenuButton != null && mainCanvas != null)
				spriteMenu.drawAFrame(mainCanvas, 0, menuTopX,
						menuTopY + i
								* (menuElementHeight + menuElementSpace));
			fontsmall.drawString(mainCanvas, mainGameLib.getResources()
					.getString(menu[i]), menuTopX, menuTopY + i
					* (menuElementHeight + menuElementSpace),
					BitmapFont.ALIGN_CENTER);
		}
	}
}
